
*===================================================================*
*   BIHAR EVALUATION OF SOCIAL FRANCHISING AND TELEMEDICINE (BEST)
*                    Comparison Tables VIGNETTE
*====================================================================*


*====================================================================*
* Diarrhoea
* Fraction of Providers who Asked Key Diagnostic Questions, Diagnosis and Treatment
*====================================================================*

* Open data BASELINE
  use "$prodata1\vignette_diarrhea", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata1\providers_interview_1st", keepus(treat sample1)
  keep if _merge==3
  drop _merge

* Sample (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==395

* Knowledge score
  sum vig_theta_mle_q12_std
  gen     know_score = (vig_theta_mle_q12_std>=r(mean))
  lab var know_score "=1 if above mean"

* Loop for Diarrhoea in Baseline

* Fraction of positive response (vig_ITEM)
  forvalues n=0/1 {
    mat table_base_d`n'=J(31,4,.)
    mat colnames table_base_d`n' = n mean sd .
    count if treat==`n'
    mat table_base_d`n'[31,1]=r(N)
    local i 1
    foreach x in 1 2 3 4 5 6 7 8 9 10 12 13 14 16 17 18 19 20 {
      sum vig_item`x' if treat==`n'
      mat table_base_d`n'[`i',1]==r(N)*r(mean)
      mat table_base_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_base_d`n'[`i',3]==r(sd)
      local i = `i' +1
    }
  }

* Diagnosis and Treatment
  gen miss=.
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  local table "antib_dontknow miss know_score miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  forvalues n=0/1 {
    local i 20
    foreach var of local table {
      sum `var' if treat==`n'
      mat table_base_d`n'[`i',1]==r(N)*r(mean)
      mat table_base_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_base_d`n'[`i',3]==r(sd)
      local i = `i'+1
      }
   mat table_base_d=nullmat(table_base_d), table_base_d`n'
   mat drop table_base_d`n'
    }


* Open data FOLLOW UP
  use "$prodata2\vignette_diarrhea", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata2\providers_interview_2nd", keepus(treat TPC RHP WHP WHP_oversampled sample1)
  keep if _merge==3
  drop _merge

* Sample (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==415

* Define group
  gen     group = 1 if treat==0
  replace group = 2 if treat==1 & WHP==0
  replace group = 3 if treat==1 & WHP==1
  tab group WHP

* ORS and Antibiotics prescription
  tab ORS if WHP_oversampled==0
  gen antib = (nantibiotics>0) & nantibiotics!=.
  gen     ORS_antib = 0
  replace ORS_antib = 1 if ORS==1 & antib==1
  table group if WHP_oversampled==0, c(mean ORS mean antib mean ORS_antib)

* Knowledge score
  sum vig_theta_mle_q12_std
  gen     know_score = (vig_theta_mle_q12_std>=r(mean))
  lab var know_score "=1 if above mean"

* Loop for Diarrhoea in follow up
/*non-implementation and implementation areas at follow up*/ 

* Fraction of positive response (vig_ITEM)
  forvalues n=1/3 {
    mat table_foll_d`n'=J(31,4,.)
    mat colnames table_foll_d`n' = n mean sd .
    count if group==`n'
    mat table_foll_d`n'[31,1]=r(N)
    local i 1
    foreach x in 1 2 3 4 5 6 7 8 9 10 12 13 14 16 17 18 19 20 {
      sum vig_item`x' if group==`n'
      mat table_foll_d`n'[`i',1]==r(N)*r(mean)
      mat table_foll_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_foll_d`n'[`i',3]==r(sd)
      local i = `i' +1
      }
    }

* Diagnosis and Treatment

  gen miss=.
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  local table "antib_dontknow miss know_score miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  forvalues n=1/3 {
    local i 20
    foreach var of local table {
      sum `var' if group==`n'
      mat table_foll_d`n'[`i',1]==r(N)*r(mean)
      mat table_foll_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_foll_d`n'[`i',3]==r(sd)
      local i = `i'+1
      }
   mat table_foll_d=nullmat(table_foll_d), table_foll_d`n'
   mat drop table_foll_d`n'
    }


* Append tables baseline + follow up
  mat table_d = table_base_d, table_foll_d

* Appending one above the other for figures
/* First 31 observation belongs to non-implementation areas while the rest to implementation ones*/
  matselrc table_base_d base1, r(1/31) c(2)
  matselrc table_foll_d foll1, r(1/31) c(2)
  mat noimp = base1, foll1

  matselrc table_base_d base2, r(1/31) c(6)
  matselrc table_foll_d foll2, r(1/31) c(6)
  mat imp = base2, foll2
  mat figure_d = noimp\imp
  mat colnames figure_d = before after
  mat drop base1 base2 foll1 foll2 noimp imp


*====================================================================*
*                          TESTING MEANS 
* APPENDIX TABLES A3
* (1) Compare group 1 and group 3
* (2) Compare group 2 ang group 4
* (3) Compare group 4 and group 5
*====================================================================*

* Open data BASELINE and append
  use          "$prodata1\vignette_diarrhea", clear
  append using "$prodata2\vignette_diarrhea"

* Sample (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==810

* Test correct diagnosis baseline vs follow up
  sum dx_type if wave==1
  sum dx_type if wave==2
  reg dx_type wave, cluster(cluster)
  clchi2 dx_type wave, cluster(cluster)

* Number of medicines prescribed
  bys wave: sum nmedicines
  bys wave: sum nmedicines if WHP!=1
  reg nmedicines wave, cluster(cluster)


* Groups
  gen     group = 1 if treat==0 & wave==1
  replace group = 2 if treat==1 & wave==1
  replace group = 3 if treat==0 & wave==2
  replace group = 4 if treat==1 & wave==2 & WHP==0
  replace group = 5 if treat==1 & wave==2 & WHP==1

  gen     compare13 = .
  replace compare13 = 0 if group==1
  replace compare13 = 1 if group==3
  lab var compare13 "before-after comparison in Non-Implementation Areas"

  gen     compare24 = .
  replace compare24 = 0 if group==2
  replace compare24 = 1 if group==4
  lab var compare24 "before-after comparison in Implementation Areas"

  gen     compare45 = .
  replace compare45 = 0 if group==4
  replace compare45 = 1 if group==5
  lab var compare45 "Non-WHP vs WHP in Implementation Areas"

* Start loop by comparison group
  foreach c in 13 24 45 {

  * Define matrix to store results
    mat appendix_table_comp`c'= J(30,7,.)
    mat colnames appendix_table_comp`c' = mean0 mean1 pvalue Lci Uci g_pval empty

  * Loop over variables
    local r 1
    foreach x in 1 2 3 4 5 6 7 8 9 10 12 13 14 16 17 18 19 20 {

    * Item
      reg vig_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 vig_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)

      local r = `r'+1
      }
    }


* Knowledge score
  sum vig_theta_mle_q12_std if wave==1
  gen     know_score = .
  replace know_score = (vig_theta_mle_q12_std>=r(mean)) if wave==1
  sum vig_theta_mle_q12_std if wave==2
  replace know_score = (vig_theta_mle_q12_std>=r(mean)) if wave==2
  lab var know_score "=1 if above mean"

* Diagnosis and Treatment
  gen miss=.
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  local table "antib_dontknow miss know_score miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"


  quietly foreach c in 13 24 45 {
  local r=20
    foreach var of local table {
      if "`var'"=="miss" local r = `r'+1       //jump miss variables//
      else {
      reg `var' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 `var' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)
      local r = `r'+1
      }
    }
  }

* Export Appendix Table with mean comparison
  mat appendix_table_comp = appendix_table_comp13, appendix_table_comp24, appendix_table_comp45
  mat drop appendix_table_comp13 appendix_table_comp24 appendix_table_comp45
  preserve
  drop _all
  svmat2 appendix_table_comp, rnames(variables)
  order variables, first
  outsheet using "$results\A3_diarrhea_vig.xls", replace
  restore










*====================================================================*
* PNEUMONIA
* Fraction of Providers who Asked Key Diagnostic Questions, Diagnosis and Treatment
*====================================================================*

* Open data BASELINE
  use "$prodata1\vignette_pneumonia", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata1\providers_interview_1st", keepus(treat sample1)
  keep if _merge==3
  drop _merge

* Sample (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==395

* Knowledge score
  sum vig_theta_mle_q12_std
  gen     know_score = (vig_theta_mle_q12_std>=r(mean))
  lab var know_score "=1 if above mean"

* Loop for Pneumonia in Baseline

* Fraction of positive response (vig_ITEM)
  forvalues n=0/1 {
    mat  table_base_p`n'=J(31,4,.)
    mat colnames table_base_p`n' = n mean sd .
    count if treat==`n'
    mat table_base_p`n'[31,1]=r(N)
    local i 1
    forvalues x = 1/18 {
      sum vig_item`x' if treat==`n'
      mat table_base_p`n'[`i',1]==r(N)*r(mean)
      mat table_base_p`n'[`i',2]==round(r(mean)*100, .1)
      mat table_base_p`n'[`i',3]==r(sd)
      local i = `i' +1
    }
  }

* Diagnosis and Treatment
  gen miss=.
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  local table "antib_dontknow miss know_score miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  forvalues n=0/1 {
    local i 20
    foreach var of local table {
      sum `var' if treat==`n'
      mat table_base_p`n'[`i',1]==r(N)*r(mean)
      mat table_base_p`n'[`i',2]==round(r(mean)*100, .1)
      mat table_base_p`n'[`i',3]==r(sd)
      local i = `i'+1
      }
   mat table_base_p=nullmat(table_base_p), table_base_p`n'
   mat drop table_base_p`n'
    }


* Open data FOLLOW UP
  use "$prodata2\vignette_pneumonia", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata2\providers_interview_2nd", keepus(treat TPC RHP WHP sample1)
  keep if _merge==3
  drop _merge

* Sample (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==415

* Define group
  gen     group = 1 if treat==0
  replace group = 2 if treat==1 & WHP==0
  replace group = 3 if treat==1 & WHP==1
  tab group WHP

* Sample selection
/*NOTE: I will keep those with completed survey and categories 1 of sample4*/
  keep if sample1==1 & sample4==1

* Knowledge score
  sum vig_theta_mle_q12_std
  gen     know_score = (vig_theta_mle_q12_std>=r(mean))
  lab var know_score "=1 if above mean"

* Loop for Pneumonia in follow up

  * Fraction of positive response (vig_ITEM)
    forvalues n=1/3 {
      mat table_foll_p`n'=J(31,4,.)
      mat colnames table_foll_p`n' = n mean sd .
      count if group==`n'
      mat table_foll_p`n'[31,1]=r(N)
      local i 1
  forvalues x = 1/18 {
    sum vig_item`x' if group==`n'
    mat table_foll_p`n'[`i',1]==r(N)*r(mean)
    mat table_foll_p`n'[`i',2]==round(r(mean)*100, .1)
    mat table_foll_p`n'[`i',3]==r(sd)
    local i = `i' +1
    }
  }


  * Diagnosis and Treatment
    gen miss=.
    gen dx_type_if=dx_type if dx_any==1
    gen tx_type_if=tx_type if tx_any==1
    local table "antib_dontknow miss know_score miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

    forvalues n=1/3 {
      local i 20
      foreach var of local table {
        sum `var' if group==`n'
        mat table_foll_p`n'[`i',1]==r(N)*r(mean)
        mat table_foll_p`n'[`i',2]==round(r(mean)*100, .1)
        mat table_foll_p`n'[`i',3]==r(sd)
        local i = `i'+1
        }
     mat table_foll_p=nullmat(table_foll_p), table_foll_p`n'
     mat drop table_foll_p`n'
      }



* Append tables baseline + follow up
  mat table_p = table_base_p, table_foll_p


* Appending one above the other for figures
/* First 31 observation belongs to non-implementation areas while the rest to implementation ones*/
  matselrc table_base_p base1, r(1/31) c(2)
  matselrc table_foll_p foll1, r(1/31) c(2)
  mat noimp = base1, foll1

  matselrc table_base_p base2, r(1/31) c(6)
  matselrc table_foll_p foll2, r(1/31) c(6)
  mat imp = base2, foll2
  mat figure_p = noimp\imp
  mat colnames figure_p = before after
  mat drop base1 base2 foll1 foll2 noimp imp


* Export tables
  local table "d p"
  foreach t of local table {
    preserve
    drop _all
    svmat2 table_`t', rnames(variables)
    cap order variables, first
    foreach num in 2 3 6 7 10 11 14 15 18 19 {
      rename table_`t'`num' table_`t'`num'_old
      gen str8 table_`t'`num'=string(table_`t'`num'_old, "%9.2f")
      replace table_`t'`num'="" if table_`t'`num' == "."
      drop table_`t'`num'_old
      }

    order table_`t'1, after(variables)
    forvalues n=19(-1)2 {
      order table_`t'`n', after(table_`t'1)
    }
    outsheet using "$results\table_`t'_vignette.xls", replace
    restore
    }



*====================================================================*
*                          TESTING MEANS 
* APPENDIX TABLE A4
* (1) Compare group 1 and group 3
* (2) Compare group 2 ang group 4
* (3) Compare group 4 and group 5
*====================================================================*

* Open data BASELINE and append
  use          "$prodata1\vignette_pneumonia", clear
  append using "$prodata2\vignette_pneumonia"

* Sample (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==810

* Groups
  gen     group = 1 if treat==0 & wave==1
  replace group = 2 if treat==1 & wave==1
  replace group = 3 if treat==0 & wave==2
  replace group = 4 if treat==1 & wave==2 & WHP==0
  replace group = 5 if treat==1 & wave==2 & WHP==1

  gen     compare13 = .
  replace compare13 = 0 if group==1
  replace compare13 = 1 if group==3
  lab var compare13 "before-after comparison in Non-Implementation Areas"

  gen     compare24 = .
  replace compare24 = 0 if group==2
  replace compare24 = 1 if group==4
  lab var compare24 "before-after comparison in Implementation Areas"

  gen     compare45 = .
  replace compare45 = 0 if group==4
  replace compare45 = 1 if group==5
  lab var compare45 "Non-WHP vs WHP in Implementation Areas"

* Start loop by comparison group
  foreach c in 13 24 45 {

  * Define matrix to store results
    mat appendix_table_comp`c'= J(30,7,.)
    mat colnames appendix_table_comp`c' = mean0 mean1 pvalue Lci Uci g_pval empty

  * Loop over variables
    local r 1
    forvalues x = 1/18 {

    * Item
      reg vig_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 vig_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)

      local r = `r'+1
      }
    }


* Knowledge score
  sum vig_theta_mle_q12_std if wave==1
  gen     know_score = .
  replace know_score = (vig_theta_mle_q12_std>=r(mean)) if wave==1
  sum vig_theta_mle_q12_std if wave==2
  replace know_score = (vig_theta_mle_q12_std>=r(mean)) if wave==2
  lab var know_score "=1 if above mean"

* Diagnosis and Treatment
  gen miss=.
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  local table "antib_dontknow miss know_score miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"


  quietly foreach c in 13 24 45 {
  local r=20
    foreach var of local table {
      if "`var'"=="miss" local r = `r'+1       //jump miss variables//
      else {
      reg `var' compare`c', cluster(cluster)
  mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
  mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
  mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

  local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
  matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

  local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
  matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

  clchi2 `var' compare`c', cluster(cluster)
  mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)
  local r = `r'+1
      }
    }
  }

* Export Appendix Table with mean comparison
  mat appendix_table_comp=appendix_table_comp13, appendix_table_comp24, appendix_table_comp45
  mat drop appendix_table_comp13 appendix_table_comp24 appendix_table_comp45
  preserve
  drop _all
  svmat2 appendix_table_comp, rnames(variables)
  order variables, first
  outsheet using "$results\A4_pneumonia_vig.xls", replace
  restore






*====================================================================*
* Figure 1 - Diarrhoea AND PNEUMONIA
* Fraction of Providers who Asked Key Diagnostic Questions
*====================================================================*

  preserve
  drop _all

* Diarrhoea
  svmat2 figure_d, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=31
  replace area = "Implementation Area" if _n>31
  drop if (_n>=50 & _n<=62) | (_n>=19 & _n<=31)

  destring variables, gen(item) ignore("r")
  gen item2=""
  replace item2 = "Fever/child warm"         if item==1
  replace item2 = "Urine normal/urine color" if item==2
  replace item2 = "Time of last urination"   if item==3
  replace item2 = "Nature of stool"          if item==4
  replace item2 = "Frequency of stool"       if item==5
  replace item2 = "Quantity of stool"        if item==6
  replace item2 = "Blood or mucus in the stools" if item==7
  replace item2 = "Worms in stool"           if item==8
  replace item2 = "Foul-smelling stool"      if item==9
  replace item2 = "Stomachache"              if item==10
  replace item2 = "Child is weak"            if item==11
  replace item2 = "Vomiting"                 if item==12
  replace item2 = "Drinking a lot of water"  if item==13
  replace item2 = "Weight"                   if item==14
  replace item2 = "Temperature"              if item==15
  replace item2 = "Mucous membranes"         if item==16
  replace item2 = "Skin color and turgor"    if item==17
  replace item2 = "Palpation of the abdomen" if item==18

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area"
  lab val area2 area2

  twoway (pcarrow item before item after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item before, pstyle(p1) ms(o)) ///
       (scatter item after, pstyle(p6) ms(S) msize(small)) , by(area2, note("") legend(off) title("Diarrhoea")) ///
  ylab(1 "Fever/child warm" 2 "Urine normal/urine color" 3 "Time of last urination" 4 "Nature of stool" 5 "Frequency of stool" 6 "Quantity of stool" 7 "Blood or mucus in the stools" 8 "Worms in stool" 9 "Foul-smelling stool" 10 "Stomachache" 11 "Child is weak" 12 "Vomiting" 13 "Drinking a lot of water" 14 "Weight" 15 "Temperature" 16 "Mucous membranes" 17 "Skin color and turgor" 18 "Palpation of the abdomen", angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Questions and Examinations - Vignette", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small)) ///
  scheme(s2color) name(fig1_d, replace) fxsize(100)


* Pneumonia
  drop _all
  svmat2 figure_p, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=31
  replace area = "Implementation Area" if _n>31
  drop if (_n>=50 & _n<=62) | (_n>=19 & _n<=31)

  destring variables, gen(item) ignore("r")
  gen item2=""
  replace item2 = "High fever"         if item==1
  replace item2 = "Cough continuous"   if item==2
  replace item2 = "Fever and cough start five days ago" if item==3
  replace item2 = "Runny/blocked nose" if item==4
  replace item2 = "Breathing rapidly"  if item==5
  replace item2 = "Nostrils flaring when breathing" if item==6
  replace item2 = "Skin b/w the ribs/stomach moves inward" if item==7
  replace item2 = "Sounds since difficult breasthing" if item==8
  replace item2 = "Breathlessness in the past"      if item==9
  replace item2 = "Weight"             if item==10
  replace item2 = "Respiration rate"   if item==11
  replace item2 = "Auscultation of chest and heart" if item==12
  replace item2 = "Pulse rate"         if item==13
  replace item2 = "Temperature"        if item==14
  replace item2 = "Examination of chest"  if item==15
  replace item2 = "Chest radiograph"   if item==16
  replace item2 = "Total Leukocyte Count (TLC)" if item==17
  replace item2 = "WBC differential"   if item==18

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area", replace
  lab val area2 area2

  twoway (pcarrow item before item after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item before, pstyle(p1) ms(o)) ///
       (scatter item after, pstyle(p6) ms(S) msize(small)) , by(area2, note("") title("Pneumonia")) ///
  ylab(1 "High fever" 2 "Cough continuous" 3 "Fever & cough start five days ago" 4 "Runny/blocked nose" 5 "Breathing rapidly" 6 "Nostrils flaring" 7 "Skin b/w ribs/stomach inward" 8 "Sounds since difficult breasthing" 9 "Breathlessness in the past" 10 "Weight" 11 "Respiration rate" 12 "Auscultation of chest and heart" 13 "Pulse rate" 14 "Temperature" 15 "Examination of chest" 16 "Chest radiograph" 17 "Total Leukocyte Count (TLC)" 18 "WBC differential", angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Questions and Examinations - Vignette", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small))   ///
  scheme(s2color) name(fig1_p, replace) 

* Figure 1
  graph combine fig1_d fig1_p, col(1) ysize(16) xsize(11.0) graphregion(color(white)) xcommon name(Figure1, replace) title("{it:{bf:Figure 1:}} {bf: Performance of Providers on Diagnostic Questions and Tests on Vignette Interviews}" "{bf: at Baseline and Follow-up, by WHP-Sky Implementation Area}", size(vsmall) ) note("Notes: Implementation area indicates study clusters where WHP-Sky program was implemented (50 out of 80 clusters).", size(tiny))
  graph export "$graphs\Figure1.emf", replace

  restore


*====================================================================*
* Figure 2 - Diarrhoea AND PNEUMONIA
* Providers Knowledge, Diagnosis and Treatment: Fraction of Providers
*====================================================================*

  preserve
  drop _all

* Diarrhoea
  svmat2 figure_d, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=31
  replace area = "Implementation Area" if _n>31
  keep if variables=="r20" | variables=="r22" | variables=="r24" | variables=="r25" | variables=="r26" | variables=="r28" | variables=="r29" | variables=="r30"

  destring variables, gen(item) ignore("r")
  recode item (20=1) (22=2) (24=3) (25=4) (26=5) (28=6) (29=7) (30=8), gen(item2)

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area", replace
  lab val area2 area2

  twoway (pcarrow item2 before item2 after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item2 before, pstyle(p1) ms(o)) ///
       (scatter item2 after, pstyle(p6) ms(S) msize(small)), by(area2, note("") legend(off) title("Diarrhoea")) ///
  ylab(1 "Has expressed not to give antibiotics when given" 2 "If knowledge score above mean" 3 "Gave any diagnosis" 4 "Correct diagnosis" 5 "Correct diagnosis (if any)" 6 "Gave any treatment" 7 "Correct treatment" 8 "Correct Treatment (if any)" , angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Other Questions, Diagnosis and Treatment - Vignette", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small)) ///
  scheme(s2color) name(fig2_d, replace)

* Pneumonia
  drop _all
  svmat2 figure_p, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=31
  replace area = "Implementation Area" if _n>31
  keep if variables=="r20" | variables=="r22" | variables=="r24" | variables=="r25" | variables=="r26" | variables=="r28" | variables=="r29" | variables=="r30"

  destring variables, gen(item) ignore("r")
  recode item (20=1) (22=2) (24=3) (25=4) (26=5) (28=6) (29=7) (30=8), gen(item2)

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area", replace
  lab val area2 area2

  twoway (pcarrow item2 before item2 after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item2 before, pstyle(p1) ms(o)) ///
       (scatter item2 after, pstyle(p6) ms(S) msize(small)), by(area2, note("") title("Pneumonia")) ///
  ylab(1 "Has expressed not to give antibiotics when given" 2 "If knowledge score above mean" 3 "Gave any diagnosis" 4 "Correct diagnosis" 5 "Correct diagnosis (if any)" 6 "Gave any treatment" 7 "Correct treatment" 8 "Correct Treatment (if any)", angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Other Questions, Diagnosis and Treatment - Vignette", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small))  xtitle("Percentage of Providers", size(small)) ///
  scheme(s2color) name(fig2_p, replace) 

* Figure 2
  graph combine fig2_d fig2_p, col(1) ysize(16) xsize(10.0) graphregion(color(white)) xcommon name(Figure2, replace) title("{bf:Figure 2: Performance of Providers on Diagnoses Made and Treatments Prescribed on Vignette}" "{bf: Interviews at Baseline and Follow-up, by WHP-Sky Implementation Area}",size(vsmall)) note(`"Notes: Implementation Area indicates study clusters where WHP-Sky program was implemented (50 out of 80 clusters). "Has expressed not to give"' `"antibiotics" represents percentage of providers who prescribed antibiotics on vignette interview, but claimed that the drug(s) that they prescribed was not"' `"an antibiotic. "Knowledge score" is the item response score, based on questions asked to interviewers. "Correct Treatment" is percentage of all providers"' `"in the group who prescribed the correct treatment while "Correct treatment (if any)" is the percentage among those giving any treatment."', size(tiny))
  graph export "$graphs\Figure2.emf", replace


  restore
